import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:city_pickers/city_pickers.dart'; //
import '../controllers/address_add_controller.dart';
import '../../../../utils/screenAdapter.dart';

class AddressAddView extends GetView<AddressAddController> {
  const AddressAddView({super.key});

  Widget _inputField({
    required String label,
    required String placeholer,
    BuildContext? context,
  }) {
    return Container(
      padding: EdgeInsets.only(
        bottom: ScreenAdapter.height(16),
        top: ScreenAdapter.height(16),
      ),
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(
            color: Colors.black12,
            width: ScreenAdapter.height(1),
          ),
        ),
      ),
      child: Row(
        children: [
          Text(
            label,
            style: TextStyle(
              fontSize: ScreenAdapter.fontSize(30),
              fontWeight: FontWeight.bold,
            ),
          ),
          SizedBox(width: ScreenAdapter.width(24)),
          Expanded(
            child: label == "所在地区"
                ? InkWell(
                    onTap: () async {
                      Result? result = await CityPickers.showCityPicker(
                        context: context!,
                      );
                      // type 2
                      // Result? result = await CityPickers.showFullPageCityPicker(
                      //   context: context!,
                      // );
                      print("result $result");
                    },
                    child: Padding(
                      padding: EdgeInsets.only(
                        top: ScreenAdapter.height(36),
                        bottom: ScreenAdapter.height(36),
                      ),
                      child: Text(
                        placeholer,
                        style: TextStyle(
                          fontSize: ScreenAdapter.fontSize(28),
                          color: Colors.black54,
                        ),
                      ),
                    ),
                  )
                : TextField(
                    decoration: InputDecoration(
                      hintText: placeholer,
                      hintStyle: TextStyle(
                        fontSize: ScreenAdapter.fontSize(28),
                        color: Colors.black54,
                      ),
                      border: InputBorder.none,
                    ),
                  ),
          ),
        ],
      ),
    );
  }

  Widget _pageBody(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(
        left: ScreenAdapter.width(20),
        right: ScreenAdapter.width(20),
        bottom: ScreenAdapter.height(132),
      ),
      child: Column(
        children: [
          _inputField(label: "姓名", placeholer: "请输入姓名"),
          _inputField(label: "电话", placeholer: "请输入电话"),
          _inputField(label: "所在地区", placeholer: "请选择所在地区", context: context),
          _inputField(label: "详细地址", placeholer: "请输入详细地址"),
          _bottomBar(),
        ],
      ),
    );
  }

  Widget _bottomBar() {
    return Container(
      margin: EdgeInsets.only(top: ScreenAdapter.height(300)),
      width: double.infinity,
      color: Colors.white,
      padding: EdgeInsets.only(
        left: ScreenAdapter.width(20),
        right: ScreenAdapter.width(20),
      ),
      child: ElevatedButton(
        style: ButtonStyle(
          padding: WidgetStateProperty.all(
            EdgeInsets.symmetric(
              vertical: ScreenAdapter.height(ScreenAdapter.height(80)),
            ), // 上下和左右两边对称设置内边距
          ),
          backgroundColor: WidgetStateProperty.all(Colors.orange),
          foregroundColor: WidgetStateProperty.all(Colors.white),
        ),
        onPressed: () {
          // Get.toNamed("/address-add");
        },
        child: Text("保存"),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(title: const Text('新建收货地址')),
      body: _pageBody(context),
    );
  }
}
